package com.an.cloud.controller;

import cn.hutool.core.date.DateUtil;
import com.an.cloud.apis.PayFeignApi;
import com.an.cloud.entities.PayDTO;
import com.an.cloud.resp.ResultData;
import com.an.cloud.resp.ReturnCodeEnum;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @auther zzyy
 * @create 2023-12-22 22:33
 */
@RestController
public class OrderController {

    @Resource
    private PayFeignApi payFeignApi;


    /**
     * 添加订单
     *
     * @param payDTO 支付dto
     * @return {@link ResultData }
     * @author: ANHE
     * @createDate: 2024/03/14
     * @version: 1.0.0
     */
    @PostMapping("/feign/pay/add")
    public ResultData addOrder(@RequestBody PayDTO payDTO) {
        return payFeignApi.addPay(payDTO);
    }

    /**
     * 添加订单
     *
     * @param id id
     * @return {@link ResultData }
     * @author: ANHE
     * @createDate: 2024/03/14
     * @version: 1.0.0
     */

    @GetMapping("/feign/pay/get/{id}")
    public ResultData getPayInfo(@PathVariable("id") Integer id)
    {
        System.out.println("-------支付微服务远程调用，按照id查询订单支付流水信息");
        ResultData resultData = null;
        try
        {
            System.out.println("调用开始-----:"+DateUtil.now());
            resultData = payFeignApi.getPayInfo(id);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("调用结束-----:"+DateUtil.now());
            ResultData.fail(ReturnCodeEnum.RC500.getCode(),e.getMessage());
        }
        return resultData;
    }


    /**
     * 添加订单
     *
     * @return {@link String }
     * @author: ANHE
     * @createDate: 2024/03/14
     * @version: 1.0.0
     */
    @GetMapping("/feign/pay/myLb")
    public String myLb() {
        return payFeignApi.myLb();
    }
}
